{% extends "master.html" %}
{% from "_formhelpers.html" import render_field_in_row %}

{% block title %}Host{% endblock %}
{%block tag %}home{% endblock %}

{% block header %}
<link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css"
  rel="stylesheet">
{% endblock %}

{% block content %}
<h2>Host {{ host.name }}
  <form class="icon inline" method="POST"
    action="{{ url_for('host_drop', host_id=host.id) }}">
  {{ form.csrf_token }}
    <button
      onclick="return confirm('You sure you want to delete this host?');"
      title="Delete host">
      <span class="icon icon-trash blue"></span>
    </button>
  </form>
</h2>

<p>
  Back to <a href="{{ url_for('site_view', site_id=host.site_id) }}">
    {{ host.site.name }}
  </a>
</p>

<form action="" method="POST">
  <table>
      {{ render_field_in_row(form.name,
        after="FQDN of server as seen by a public end user") }}
    {% if is_admin %}
    {{ render_field_in_row(form.admin_active,
        after="Uncheck this box to temporarily disable this host, it will
              be removed from public listings.") }}
    {% endif %}
    {{ render_field_in_row(form.user_active,
        after="Uncheck this box to temporarily disable this host, it will
              be removed from public listings.") }}
    {{ render_field_in_row(form.disable_reason) }}
    {{ render_field_in_row(form.country,
        after="2-letter ISO country code") }}
    {{ render_field_in_row(form.bandwidth_int,
        after="integer megabits/sec, how much bandwidth this host can serve") }}
    {{ render_field_in_row(form.private,
        after="e.g. not available to the public, an internal private mirror") }}
    {{ render_field_in_row(form.internet2,
        after="on Internet2") }}
    {{ render_field_in_row(form.internet2_clients,
        after="serves Internet2 clients, even if private") }}
    {{ render_field_in_row(form.asn,
        after="Autonomous System Number, used in BGP routing tables.") }}
    {{ render_field_in_row(form.asn_clients,
        after="Serve all clients from the same ASN.  Used for ISPs,
               companies, or schools, not personal networks.") }}
    {{ render_field_in_row(form.robot_email,
        after="email address, will receive notice of upstream content updates") }}
    {{ render_field_in_row(form.comment,
        after="text, anything else you'd like a public end user to know
               about your mirror") }}
    {{ render_field_in_row(form.max_connections,
        after="Maximum parallel download connections per client, suggested
               via metalinks.") }}
  </table>
  <p class="buttons indent">
    <input type="submit" class="submit positive button" value="Update">
    <a href="{{ url_for('index') }}">
      <input type="button" value="Cancel" class="button">
    </a>
    {{ form.csrf_token }}
  </p>
</form>

<p>
{% if host.private %}Last Checked In: {{ host.last_checked_in or '-' }} <br />{% endif %}
{% if not host.private %}Last Crawled: {% if host.last_crawled %} {{ host.last_crawled
  }} <a href="{{url_for('index')}}crawler/{{host.id}}.log">[Log]</a> {% else %} - {% endif %} <br />
Last Crawl Duration: {{ host.last_crawl_duration }} seconds
{% if host.crawl_failures > 0 %}<br/>Number of consecutive crawl failures: {{ host.crawl_failures }} {% endif %}{% endif %}
</p>

{%- if config['MASTER_RSYNC_ACL'] -%}
<h3>
  Master rsync server Access Control List IPs
</h3>
<p>
  These host DNS names and/or IP addresses will be allowed to rsync from
  the master rsync/ftp servers. List here all the machines that you use for
  pulling.
</p>

<a class="icon icon-plus-sign blue"
  href="{{ url_for('host_acl_ip_new', host_id=host.id) }}"> [add]</a>
{% if host.acl_ips %}
  <ul>
  {% for acl in host.acl_ips %}
  <li>
      <form class="icon" method="POST"
        action="{{ url_for('host_acl_ip_delete', host_id=host.id, host_acl_ip_id=acl.id) }}">
      {{ acl.ip }}
      {{ form.csrf_token }}
        <button
          onclick="return confirm('You sure you want to delete this ACL?');"
          title="Delete ACL IP">
          <span class="icon icon-trash blue"></span>
        </button>
      </form>
    </li>
  {% endfor %}
  </ul>
{% endif %}
{%- endif -%}{# MASTER_RSYNC_ACL ##}

<h3>
  Site-local Netblocks
</h3>
<p>
  Netblocks are used to try to guide and end user to a site-specific mirror.
  For example, a university might list their netblocks, and the mirrorlist
  CGI would return the university-local mirror rather than a country-local
  mirror. Format is one of 18.0.0.0/255.0.0.0, 18.0.0.0/8, an IPv6
  prefix/length, or a DNS hostname. Values must be public IP addresses (no
  RFC1918 private space addresses).
</p>

<a class="icon icon-plus-sign blue"
  href="{{ url_for('host_netblock_new', host_id=host.id) }}"> [add]</a>
{% if host.netblocks %}
  <ul>
  {% for netblock in host.netblocks %}
    <li>
      <form class="icon" method="POST"
        action="{{ url_for('host_netblock_delete', host_id=host.id,
                   host_netblock_id=netblock.id) }}">
      {{ netblock.netblock }}
      {{ form.csrf_token }}
        <button
          onclick="return confirm('You sure you want to delete this netblock?');"
          title="Delete netblock">
          <span class="icon icon-trash blue"></span>
        </button>
      </form>
    </li>
  {% endfor %}
  </ul>
{% endif %}

<h3>
  Peer ASNs
</h3>
<p>
  Peer ASNs are used to guide an end user on nearby networks to our mirror.
  For example, a university might list their peer ASNs, and the mirrorlist
  CGI would return the university-local mirror rather than a country-local
  mirror. You must be in the MirrorManager administrators group in order to
  create new entries here.
</p>

{% if is_admin %}
<a class="icon icon-plus-sign blue"
  href="{{ url_for('host_asn_new', host_id=host.id) }}"> [add]</a>
{% endif %}
{% if host.peer_asns %}
  <ul>
  {% for asn in host.peer_asns %}
    <li>
    {% if is_admin %}
      <form class="icon" method="POST"
        action="{{ url_for('host_asn_delete', host_id=host.id,
                   host_asn_id=asn.id) }}">
        {{ asn.asn }}
        {{ form.csrf_token }}
        <button
          onclick="return confirm('You sure you want to delete this Peer ASN?');"
          title="Delete Peer ASN">
          <span class="icon icon-trash blue"></span>
        </button>
      </form>
    {% else %}
      {{ asn.asn }}
    {% endif %}
    </li>
  {% endfor %}
  </ul>
{% endif %}

<h3>
  Countries Allowed
</h3>
<p>
  Some mirrors need to restrict themselves to serving only end users from
  their country. If you're one of these, list the 2-letter ISO code for the
  countries you will allow end users to be from. The mirrorlist CGI will
  honor this.
</p>

<a class="icon icon-plus-sign blue"
  href="{{ url_for('host_country_new', host_id=host.id) }}"> [add]</a>
{% if host.countries %}
  <ul>
  {% for country in host.countries %}
    <li>
      <form class="icon" method="POST"
        action="{{ url_for('host_country_delete', host_id=host.id,
                   host_country_id=country.id) }}">
      {{ country.country.code }}
      {{ form.csrf_token }}
        <button
          onclick="return confirm('You sure you want to delete this country?');"
          title="Delete country">
          <span class="icon icon-trash blue"></span>
        </button>
      </form>
    </li>
  {% endfor %}
  </ul>
{% endif %}


<h3>
Categories Carried
</h3>

<p>
  Hosts carry categories of software. Example Fedora categories include
  Fedora and Fedora Archive.
</p>

<a class="icon icon-plus-sign blue"
  href="{{ url_for('host_category_new', host_id=host.id) }}"> [add]</a>
{% if host.categories %}
  <ul>
  {% for category in host.categories %}
    <li>
      <form class="icon" method="POST"
        action="{{ url_for('host_category_delete', host_id=host.id,
                   hc_id=category.id) }}">
        <a href="{{ url_for('host_category', host_id=host.id,
                    hc_id=category.id) }}">
        {{ category.category.name }}
        </a>
        {{ form.csrf_token }}
        <button
          onclick="return confirm('You sure you want to delete this category?');"
          title="Delete category">
          <span class="icon icon-trash blue"></span>
        </button>
      </form>
    </li>
    {% if category.urls %}
    <li>
      <ul>
        {% for url in category.urls %}
        <li>{{ url.url }}</li>
        {% endfor %}
      </ul>
    </li>
    {% endif %}

  {% endfor %}
  </ul>
{% endif %}

{% endblock %}
